﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyWrite.API.Appicant.Command.ApproveCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyWrite.API.Controllers
{
    /// <summary>
    /// 请假审批模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ApproveController : ControllerBase
    {
        private readonly IMediator mediator;

        public ApproveController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加请假申请表命令处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<APIResult<string>> AddLeaveModel(AddLeaveModelCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 反填修改请假申请信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<LeaveModel>> FanTianLeaveModel([FromQuery] FanTianLeaveModelCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 修改请假申请表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<string>> UpdatLeaveModel([FromBody] UpdatLeaveModelCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 添加审批记录表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<string>> AddLeaveRecordModel(AddLeaveRecordModelCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除申请--Id
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        public async Task<APIResult<string>> DeleteLeaveModel([FromQuery]DeleteLeaveModelCommand request)
        { 
            return await mediator.Send(request);
        }


    }
}
